package com.hqhsc.module.manage.activity.service;

import com.hqhsc.module.common.service.ManageMemcacdedClient;
import com.hqhsc.module.front.activity.dao.VoteDao;
import com.hqhsc.module.front.activity.domain.Vote;
import com.hqhsc.module.manage.activity.dao.VoteManageDao;
import com.hqhsc.module.manage.activity.domain.Activity;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
 *
 * @author jiangyin
 */
@Service
public class VoteManageService {

	static Logger logger = LoggerFactory.getLogger(VoteManageService.class);

	@Autowired
	private ManageMemcacdedClient memcachedClient;
	@Autowired
	private VoteManageDao voteManageDao;
    @Autowired
    private VoteDao voteDao;
    @Autowired
    private Properties appProps;

    /**
     * 获取投票活动，作品列表
     * @param activity_id
     * @return
     */
    public Map<String , Object> getActivityList(int activity_id , String orderby_request , int start , int size) {

        String orderby = null;
        String orderby_type = null;
        if(StringUtils.isNotEmpty(orderby_request)) {
            orderby = orderby_request.split(",")[0];
            orderby_type = orderby_request.split(",")[1];
        }

        long total = this.voteManageDao.getVoteCount(activity_id);
        List<Vote> vote_list = this.voteManageDao.getVoteList(activity_id, start, size);

        Map<String , Object> map = new HashMap<String, Object>();
        map.put("total" , total);
        map.put("vote_list" , vote_list);
        return map;
    }

    /**
     * 审核，更新作品状态
     * @param id
     * @param origin_status
     * @return
     */
    public int productAuth(long id , int origin_status) {
         int result_status = 0;
         if(origin_status == 0) {
             result_status = 1;
         }

         return this.voteManageDao.productAuth(result_status , id , origin_status);

     }

    /**
     * 获取投票活动，作品详细
     * @param id
     * @return
     */
    public Vote getPordcutById(long id) {
        return this.voteDao.getProductById(id);
    }

}
